package com.spider.moudle.crawler.others;
import com.alibaba.fastjson.JSONObject;
import com.spider.moudle.api.realize.AbstractCrawler;
import com.spider.moudle.entity.ResponseEntity;
import com.spider.moudle.entity.Task;
import com.spider.moudle.entity.TaskType;
import com.spider.moudle.entity.WebType;
import com.spider.moudle.util.CommonUtil;
import org.jsoup.nodes.Document;

/**
 * Created by stanfordh on 07/31/18.
 */
public class TaoBaoCrawler extends AbstractCrawler {
    @Override
    public void generateTask() {

    }

    @Override
    public JSONObject crawlItem(Task task) throws Exception {
        String url = task.getUrl();
        ResponseEntity entity = null;
        try {
            entity = downloader.get(url, true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        if (entity != null && entity.getStatus_code() == 200) {
            Document document = entity.getDocument();




        }


        System.out.println(url);
        return null;
    }


    public static void main(String[] args) throws Exception {
        Task task = new Task("https://store.taobao.com/shop/view_shop.htm?user_number_id=2102058069", TaskType.USER, WebType.FORLUM, "ddd_8028471", null);
        JSONObject object = new TaoBaoCrawler().crawlItem(task);
        if(CommonUtil.isNotNull(object)) {
            System.out.println(object.toJSONString());
        } else {
            System.exit(1);
        }
    }
}
